package com.codedancer.campus.mapper;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.codedancer.campus.common.core.BaseMapper;
import com.codedancer.campus.po.Role;
import com.codedancer.campus.qo.role.RolePageSearchQo;

public interface RoleMapper extends BaseMapper<Role> {

    /**
     * 分页查询角色
     *
     * @param rolePage
     * @param rolePageSearchQo
     * @return
     */
    default IPage<Role> page(Page<Role> rolePage, RolePageSearchQo rolePageSearchQo) {
        LambdaQueryWrapper<Role> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (ObjectUtil.isNotEmpty(rolePageSearchQo.getName())) {
            lambdaQueryWrapper.like(Role::getName, rolePageSearchQo.getName());
        }
        return selectPage(rolePage, lambdaQueryWrapper);
    }
}
